/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.dao.vo;

import java.util.Date;

import com.eelpo.cmmp.core.wicket.panel.paging.ISort;
import com.eelpo.cmmp.uac.dao.vo.enumed.AuthMode;
import com.eelpo.cmmp.uac.dao.vo.enumed.Status;
import com.eelpo.cmmp.uac.dao.vo.enumed.YesOrNo;
import com.eelpo.common.util.BlankUtils;

/**
 * <pre>
 * 
 * 用户值对象(Value Object)
 *  
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class User implements ISort {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 3671984470502066760L;

	/**
	 * 用户id
	 */
	private String id;

	/**
	 * 用户名称
	 */
	private String name;

	/**
	 * 用户帐号
	 */
	private String account;

	/**
	 * 用户密码
	 */
	private String password;

	/**
	 * 手机
	 */
	private String mobile;

	/**
	 * 用户状态
	 */
	private Status status;

	/**
	 * 是否允许web登录
	 */
	private YesOrNo allowWebLogin;

	/**
	 * 启用允许接口调用
	 */
	private YesOrNo allowInterface;

	/**
	 * web鉴权模式
	 */
	private AuthMode webAuthMode;

	/**
	 * 接口鉴权模式
	 */
	private AuthMode interfaceAuthMode;

	/**
	 * 是否超级管理员
	 */
	private YesOrNo superManager;

	/**
	 * 登录时间
	 */
	private Date loginTime;

	/**
	 * 最后修改时间
	 */
	private Date lastModifiedTime;

	/**
	 * 最后修改密码时间
	 */
	private Date lastPasswordTime;

	/**
	 * 描述信息
	 */
	private String description;

	/**
	 * 排序字段
	 */
	private String sort;

	public User() {

	}

	public User(String id) {
		this.id = id;
	}

	public User(Status status, YesOrNo allowWebLogin, YesOrNo allowInterface, AuthMode webAuthMode, AuthMode interfaceAuthMode) {
		this.status = status;
		this.allowWebLogin = allowWebLogin;
		this.allowInterface = allowInterface;
		this.webAuthMode = webAuthMode;
		this.interfaceAuthMode = interfaceAuthMode;
		this.superManager = YesOrNo.NO;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public YesOrNo getAllowWebLogin() {
		return allowWebLogin;
	}

	public void setAllowWebLogin(YesOrNo allowWebLogin) {
		this.allowWebLogin = allowWebLogin;
	}

	public YesOrNo getAllowInterface() {
		return allowInterface;
	}

	public void setAllowInterface(YesOrNo allowInterface) {
		this.allowInterface = allowInterface;
	}

	public AuthMode getWebAuthMode() {
		return webAuthMode;
	}

	public void setWebAuthMode(AuthMode webAuthMode) {
		this.webAuthMode = webAuthMode;
	}

	public AuthMode getInterfaceAuthMode() {
		return interfaceAuthMode;
	}

	public void setInterfaceAuthMode(AuthMode interfaceAuthMode) {
		this.interfaceAuthMode = interfaceAuthMode;
	}

	public YesOrNo getSuperManager() {
		return superManager;
	}

	public void setSuperManager(YesOrNo superManager) {
		this.superManager = superManager;
	}

	public Date getLoginTime() {
		return loginTime;
	}

	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}

	public Date getLastModifiedTime() {
		return lastModifiedTime;
	}

	public void setLastModifiedTime(Date lastModifiedTime) {
		this.lastModifiedTime = lastModifiedTime;
	}

	public Date getLastPasswordTime() {
		return lastPasswordTime;
	}

	public void setLastPasswordTime(Date lastPasswordTime) {
		this.lastPasswordTime = lastPasswordTime;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getSort() {
		return sort;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public void setSort(String sort, String mode) {
		this.sort = sort.concat(" ").concat(mode);
	}

	@Override
	public boolean equals(Object obj) {
		if (BlankUtils.isBlank(obj) || !(obj instanceof User))
			return false;

		if (this == obj)
			return true;

		User user = (User) obj;

		if (BlankUtils.isBlank(this.id) || BlankUtils.isBlank(user.getId())) {
			return false;
		}

		return this.id.equals(user.getId());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public String toString() {
		return "User[name=" + name + ",account=" + account + "]";
	}
}
